import { combineReducers } from 'redux'
import { configureStore } from '@reduxjs/toolkit'
import signReducers from './slices/signSlice'
import storage from 'redux-persist/lib/storage'
import { persistReducer, FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER } from 'redux-persist'
import systemReducers from './slices/systemSlice'

const rootReducer = combineReducers({
  sign: signReducers,
  system: systemReducers
})

// 持久化配置
const persistConfig = {
  key: 'sign-search',
  version: 1,
  storage
}

// 持久化 rootReducer
const persistedReducer = persistReducer(persistConfig, rootReducer)

export const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER]
      }
    })
})

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
